<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>主页</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/js/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/admin/css/common.css" media="all">
    <script src="/js/layui/layui.all.js"></script>
</head>

<body class="layui-layout-body">
<div class="layui-row">
    <div class="layui-col-md2  formbox " style="margin-top: 10px">

    </div>

    <div class="layui-fluid layui-col-md8 layui-col-sm12 ">
        <div class="layui-card">
            <div class="layui-card-body" style="padding: 15px;" class="layui-row">
                <form class="layui-form" action="" >
                    <div class="layui-form-item">
                        <label class="layui-form-label">原IP:</label>
                        <div class="layui-input-block">
                            <input type="text" readonly name="ip" id="ip" required lay-verify="ip" placeholder="原IP地址"
                                   autocomplete="off" class="layui-input">
                        </div>


                    </div>

                    <div class="layui-form-item">
                        <label class="layui-form-label">新IP:</label>
                        <div class="layui-input-block">
                            <select  name="ips" id="ips"
                                     class="layui-select">

                            </select>

                        </div>
                    </div>



                    <div class="layui-form-item">
                        <div class="layui-input-block">
                            <div class="layui-footer" style="left: 0;">
                                <button type="button" class="layui-btn" id="btnAdd"  style="margin-left:10%;width: 200px">
                                     保存
                                </button>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>

    <div class="layui-col-md2 formbox">

    </div>
</div>
</body>
</html>

<script>
    var $= layui.$;
    var form = layui.form;

    $(function(){
         $.ajax({
             url:'/system/getIP',
             success:function(data){
                 $("#ip").val(data.data.ip);

                 var ips = data.data.ips;
                 for (i in ips){
                     var op = new Option(ips[i],ips[i]);
                     $("#ips")[0].append(op);
                 }
                 if (data.data.ip)
                 {
                     $("#ips").val(data.data.ip);
                 }
                 form.render("select");
             }
         });
    });

    $("#btnAdd").click(function(){
        var oldIp = $("#ip").val();
        var newIp = $("#ips").val();

        if (oldIp==newIp)
        {

            layer.msg("没有更改",{icon:2,time:1000});
            return false;
        }

        layer.confirm("确定要修改吗？可能会影响电视正常收看",["确定","取消"],function(){
            $.ajax({
                url:'/system/saveIP',
                data:{ip:newIp},
                async:true,
                success:function(data){
                    if (data.code==200)
                    {
                        layer.msg("修改成功",{icon:1,time:1000});
                        $("#ip").val(newIp);
                        return false;
                    }
                    else{
                        layer.msg("非法访问",{icon:2,time:1000});
                        return false;
                    }

                }
            });
        })

    });
</script>

